const Multer = require('koa-multer')
const { AVATAR_PATH, PICTURE_PATH, FILE_PATH } = require('../constants/file-path')

// const storage = Multer.diskStorage({
//     destination: function (req, file, cb) {
//         cb(null, FILE_PATH); //配置图片上传的目录
//     },
//     filename: function (req, file, cb) {   /*图片上传完成重命名*/
//         var fileFormat = (file.originalname).split(".");
//         cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
//     }
// });

// const fileUpload = Multer({ storage: storage });

const avatarUpload = Multer({
    dest: AVATAR_PATH
})
const pictureUpload = Multer({
    dest: PICTURE_PATH
})
const fileUpload = Multer({
    dest: FILE_PATH
})
const pictureHandler = pictureUpload.array('picture', 9)
const avatarHandler = avatarUpload.single('avatar')
const fileHandler = fileUpload.array('file', 9)
module.exports = {
    avatarHandler,
    pictureHandler,
    fileHandler
}